public class Test {
     if(head == null) {
        return head;
    }

         if(head.next == null) {
        return head;
    }

    ListNode cur = head.next;
    head.next = null;


         while( cur != null) {
        ListNode curN = cur.next;
        cur.next = head;
        head = cur;
        cur = curN;
    }
         return head;

    // if(head == null) {
    //     return head;
    // }

    // if(head.next == null) {
    //     return head;
    // }

    // ListNode cur = head;

    // while(cur.next != null) {
    //     cur.next.next = cur;
    //     cur = cur.next;
    // }

    // head.next = null;
    // head = cur;
    // return head;


    public ListNode middleNode(ListNode head) {
        if(head==null) {
            return head;
        }

        if(head.next==null) {
            return head;
        }

        ListNode fast = head;
        ListNode slow = head;

        while(fast != null && fast.next  != null) {
            fast =  fast.next.next;
            slow =  slow.next;
        }
        return slow;
    }

    public ListNode findNode(int key) {

//        if(key <= 0 || key >= len )
//        {
//            throw new IllegalAccessException("");
//        }

        if(head == null) {
            return null;
        }

        ListNode fast = head;
        ListNode slow = head;

//        int index = key-1;
//        while(index != 0) {
//            fast = fast.next;
//            index--;
//        }

        int count = 0;
        while( count != key-1) {
            fast = fast.next;
            if(fast == null) {
                return throw new IllegalAccessException("");
            }
            count++;
        }

        while(fast.next != null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;

        public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
            ListNode newhead = new ListNode();
            ListNode cur = newhead;

            while(list1 != null && list2 != null) {
                if(list1.val < list2.val) {
                    cur.next = list1;
                    list1 = list1.next;
                }else {
                    cur.next = list2;
                    list2 = list2.next;
                }
                cur = cur.next;
            }

            if(list1 == null) {
                cur.next = list2;
            }

            if(list2 == null) {
                cur.next = list1;
            }

            return newhead.next;
        }

    }


}
